package org.afs.gescol.core.dao.implementations;

import java.util.List;

import org.afs.gescol.core.dao.interfaces.TeacherManagmentDao;
import org.afs.gescol.core.dto.DataCriteria;
import org.afs.gescol.core.model.data.Teacher;
import org.afs.gescol.core.model.data.TeacherAssignment;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.scub.foundation.framework.core.dao.implementations.HibernateDaoBaseImplementation;

/**
 * Implementation of SubjectDao.
 * @autor Kobla GBENYO (kobla.gbenyo@gmail.com)
 */
public class TeacherManagmentDaoImpl extends HibernateDaoBaseImplementation implements TeacherManagmentDao {

    @Override
    public Teacher getTeacherById(Long id) {
        return load(id, Teacher.class);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TeacherAssignment> getTeacherAssignmentByCriteria(DataCriteria criteria) {
        final Criteria searchCriteria = createCriteria(TeacherAssignment.class);
        if (criteria.getSeriesId() != null) {
            searchCriteria.add(Restrictions.eq("series.id", criteria.getSeriesId()));
        }
        if (criteria.getLevelId() != null) {
            searchCriteria.add(Restrictions.eq("level.id", criteria.getLevelId()));
        }
        if (criteria.getSubjectId() != null) {
            searchCriteria.add(Restrictions.eq("subject.id", criteria.getSubjectId()));
        }
        if (criteria.getTeacherId() != null) {
            searchCriteria.add(Restrictions.eq("teacher.id", criteria.getTeacherId()));
        }
        return searchCriteria.list();
    }

}
